Gikam.addComponent(function (options) {
    return {
        // 组件名称
        name: 'KnowledgeBase',

        data: function () {
            return {
                data: {}
            }
        },

        mounted: function () {
            var _this = this
            var url = '/secure/baseline/basedata/knowledgelibrarys/refresh-knowledgelibrary'
            Gikam.getText(url).done(function (req) {
                req = JSON.parse(req)
                console.log(req)
                _this.data = req
                console.log(_this.data)
            })
        },

        methods: {
            showDownload(i) {
                this.data.FileList[i].flag = true
            },
            hideDownload(i) {
                this.data.FileList[i].flag = false
            },
            download(item) {
                // console.log(item.id)
                if (item.id) {
                    let url = Gikam.printf('/secure/baseline/basedata/knowledgelibrarys/{id}/core-file', {
                        id: item.id
                    })
                    Gikam.postText(url, Gikam.getJsonWrapper(null, [null, []])).done(function (res) {
                        res = JSON.parse(res)
                        // console.log(res)
                        Gikam.download(res.downloadUrl)
                    })
                }
            }
        },

        template: `
        <div class="main">
            <div class="main-header">
                <div class='main-header-list'>
                    <div class="main-header-list-item">{{data.header && data.header.fileName}}</div>
                    <div class="download"></div>
                    <div class="main-header-list-item">{{data.header && data.header.fileSize}}</div>
                    <div class="main-header-list-item">{{data.header && data.header.fileType}}</div>
                </div>
            </div>
            <div class="main-content">
                <div class='main-content-list'
                    v-for="(item, i) in data.FileList"
                    :key="i"
                    @mouseenter="showDownload(i)"
                    @mouseleave="hideDownload(i)"
                    >
                    <div class="main-content-list-item">{{item.fileName}}</div>
                    <div class="download">
                        <img v-if="item.flag"
                            class="download-icon"
                            src="/static/baseline/basedata/homepage/knowledgelibrary/icon.svg" alt=""
                            @click="download(item)"
                        >
                    </div>
                    <div class="main-content-list-item">{{item.fileSize}}</div>
                    <div class="main-content-list-item">{{item.fileType}}</div>
                </div>
            </div>
        </div>`
    }
})
